#include "app.h"
#include "web.h"

namespace app {
  Config cfg;
  crow::SimpleApp app;

  bool init(const std::string& cfg_file) {
    if (!app::cfg.init(cfg_file))
      return false;
    return web::add_web(app::app);
  }
  void run() {
    auto cfg = app::cfg.listen();
    auto count = cfg["thread"].i();
    auto ip = cfg["ip"].s();
    auto port = cfg["port"].i();
    if (count > 0) {
      app::app.bindaddr(ip)
        .port(port)
        .concurrency(count)
        .run();
    } else {
      app::app.bindaddr(ip)
        .port(port)
        .multithreaded()
        .run();
    }
  }
  void uninit() {}
}